package cn.edu.zjicm.wordsnet_d.BroadcastReceiver;

import cn.edu.zjicm.wordsnet_d.download.JudgeNetwork;
import cn.edu.zjicm.wordsnet_d.util.LogUtil;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

public class NetWorkStateBroadCastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
			// Intent中ConnectivityManager.EXTRA_NO_CONNECTIVITY这个关键字表示着当前是否连接上了网络，true
			// 代表网络断开 false 代表网络没有断开
			if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) {
				LogUtil.e("网络状态改变", "没有网络");
				JudgeNetwork.getInstance(context).setWifiConnected(false);
				JudgeNetwork.getInstance(context).setMobileConnected(false);// 直接设置为网络状态不可用
			} else {
				LogUtil.e("网络状态改变", "有网络");
				JudgeNetwork.getInstance(context).refreshCurrentNetWork();// 刷新网络状态
			}
		}
	}
}
